home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…eptember: Technology Seed / September 98 ADC Seed CD.toast / Language Analysis Manager / DarumaDR1Package / Examples / TextConverter / Sources / DebugUtil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.4 KB  |  185 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        DebugUtil.h
  3.     
  4.     Contains:    A Sample application for High-level text conversion
  5.  
  6.      Version:    Technology:    System 8
  7.                  Release:    Daruma Developer Release 1
  8.  
  9.      Copyright:    1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Contact:    daruma@apple.com
  12.  
  13. */
  14.  
  15.  
  16. #ifndef __DEBUGUTIL__
  17. #define __DEBUGUTIL__
  18.  
  19. #include <Types.h>
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. #if PRAGMA_IMPORT_SUPPORTED
  26. #pragma import on
  27. #endif
  28.  
  29. #if PRAGMA_ALIGN_SUPPORTED
  30. #pragma options align=mac68k
  31. #endif
  32.  
  33. extern void DebugPrint(        char *        assertionString,
  34.                             char *        exceptionString,
  35.                             char *        errorString,
  36.                             char *        fileName,
  37.                             long        lineNumber,
  38.                             void *        value);
  39.  
  40. #define QuoteExceptionString(x) #x
  41.  
  42. /********************************************************************
  43.  
  44. MACRO
  45.     require(assertion, exception)
  46.  
  47. DESCRIPTION
  48.     require will test assertion and if it fails:
  49.         break into the debugger if debugging is on.
  50.         goto exception.
  51.  
  52.  ********************************************************************/
  53. #if    DEBUG_BUILD
  54. #define require(assertion, exception)                                      \
  55.     do {                                                                \
  56.         if (assertion) ;                                                \
  57.         else {                                                            \
  58.             DebugPrint( QuoteExceptionString(assertion),                  \
  59.                         QuoteExceptionString(exception),                 \
  60.                         nil, __FILE__, __LINE__, 0);                    \
  61.             goto exception;                                                \
  62.         }                                                                \
  63.     } while (false)
  64. #else
  65. #define require(assertion, exception)                                      \
  66.     do {                                                                \
  67.         if (assertion) ;                                                \
  68.         else {                                                            \
  69.             goto exception;                                                \
  70.         }                                                                \
  71.     } while (false)
  72. #endif
  73.  
  74.  
  75. /********************************************************************
  76.  
  77. MACRO
  78.     nrequire(assertion, exception)
  79.  
  80. DESCRIPTION
  81.     nrequire will test !assertion and if it fails:
  82.         break into the debugger if debugging is on.
  83.         goto exception.
  84.  
  85.  ********************************************************************/
  86. #if    DEBUG_BUILD
  87. #define nrequire(assertion, exception)                              \
  88.     do {                                                            \
  89.         void*    __privateAssertion    = (void*)(assertion);             \
  90.                                                                     \
  91.         if (__privateAssertion) {                                    \
  92.             DebugPrint( QuoteExceptionString(assertion),            \
  93.                         QuoteExceptionString(exception), nil,        \
  94.                         __FILE__, __LINE__, __privateAssertion);    \
  95.             goto exception;                                            \
  96.         }                                                            \
  97.     } while (false)
  98. #else
  99. #define nrequire(assertion, exception)                              \
  100.     do {                                                            \
  101.         if (assertion) {                                            \
  102.             goto exception;                                            \
  103.         }                                                            \
  104.     } while (false)
  105. #endif
  106.  
  107.  
  108. /********************************************************************
  109.  
  110. MACRO
  111.     require_action(assertion, exception, action)
  112.  
  113. DESCRIPTION
  114.     require_action will test assertion and if it fails:
  115.         break into the debugger if debugging is on.
  116.         execute action.
  117.         goto exception.
  118.  
  119.  ********************************************************************/
  120. #if    DEBUG_BUILD
  121. #define require_action(assertion, exception, action)                  \
  122.     do {                                                            \
  123.         if (assertion) ;                                            \
  124.         else {                                                        \
  125.             DebugPrint( QuoteExceptionString(assertion),              \
  126.                         QuoteExceptionString(exception),            \
  127.                         nil, __FILE__, __LINE__, 0);                 \
  128.             { action }                                                \
  129.             goto exception;                                            \
  130.         }                                                            \
  131.     } while (false)
  132. #else
  133. #define require_action(assertion, exception, action)                 \
  134.     do {                                                            \
  135.         if (assertion) ;                                            \
  136.         else {                                                        \
  137.             { action }                                                \
  138.             goto exception;                                            \
  139.         }                                                            \
  140.     } while (false)
  141. #endif
  142.  
  143.  
  144. /********************************************************************
  145.  
  146. MACRO
  147.     nrequire_action(assertion, exception, action)
  148.  
  149. DESCRIPTION
  150.     nrequire_action will test !assertion and if it fails:
  151.         break into the debugger if debugging is on.
  152.         execute action.
  153.         goto exception.
  154.  
  155.  ********************************************************************/
  156. #if    DEBUG_BUILD
  157. #define nrequire_action(assertion, exception, action)                  \
  158.     do {                                                            \
  159.         void*    __privateAssertion    = (void*)(assertion);             \
  160.                                                                     \
  161.         if (__privateAssertion) {                                    \
  162.             DebugPrint( QuoteExceptionString(assertion),              \
  163.                         QuoteExceptionString(exception), nil,        \
  164.                         __FILE__, __LINE__, __privateAssertion);    \
  165.             { action }                                                \
  166.             goto exception;                                            \
  167.         }                                                            \
  168.     } while (false)
  169. #else
  170. #define nrequire_action(assertion, exception, action)                  \
  171.     do {                                                            \
  172.         if (assertion) {                                            \
  173.             { action }                                                \
  174.             goto exception;                                            \
  175.         }                                                            \
  176.     } while (false)
  177. #endif
  178.  
  179.  
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183.  
  184. #endif
  185.